<?php

class Html_Render_Div3
{
	public function render($group)
	{

		$tag = $group -> getMeta('tag', 'div');

		$xhtml = array();

		$groupTitle = $group -> getMeta('title') ? ($group -> getNoTitle() ? '' : '<div class="form-group-title">' . $group -> getMeta('title'). '</div>') : '';

		$groupDesc = $group -> getMeta('desc') ? ($group -> getNoDesc() ? '' : '<div class="form-group-desc">' . ($group -> getMeta('desc')) . '</div>') : '';

		foreach ($group->getChildren() as $ele)
		{
			$label = $ele -> getMeta('label') ? ($ele -> getNoTitle() ? '' : '<div class="form-element-label">' . ($ele -> getMeta('label')) . '</div>') : '';
			$desc = $ele -> getMeta('desc') ? ($ele -> getNoTitle() ? '' : '<div class="form-element-desc">' . ($ele -> getMeta('desc')) . '</div>') : '';
			$html = $ele -> render();
			$xhtml[] = '<div class="form-element-wrapper">' . $label . '<div class="form-element-card-outer">' . $desc . $html . '</div>' . '</div>';
		}

		return sprintf('<%s %s>%s %s %s</div></%s>', $tag, $group -> __flat(), $groupTitle, $groupDesc, implode(PHP_EOL, $xhtml), $tag);
	}

}
